package cn.qicaiwang.open.app.server.Impl;

import cn.qicaiwang.open.app.entity.Enterprise;
import cn.qicaiwang.open.app.mapper.EnterpriseMapper;
import cn.qicaiwang.open.app.server.EnterpriseService;
import cn.qicaiwang.open.common.exception.BusinessException;
import cn.qicaiwang.open.common.utils.ProvinceUtil;
import cn.qicaiwang.open.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;


@Service
public class EnterpriseServiceImpl implements EnterpriseService {

    @Autowired
    private EnterpriseMapper enterpriseMapper;

    @Override
    public List<Map<String, Object>> fuzzySearchByName(String enterpriseName, String province) {
        if (StringUtils.isBlank(province)) {
            throw new IllegalArgumentException("省份不能为空");
        }
        String tableName = "enterprise_" + ProvinceUtil.getProvinceCode(province);
        return enterpriseMapper.fuzzySearchByName(tableName,enterpriseName);
    }

    @Override
    public Page<Enterprise> pageList(Page page, String province,Enterprise enterprise) {
        try {
            if (StringUtils.isBlank(province)) {
                throw new IllegalArgumentException("省份不能为空");
            }
            String tableName = "enterprise_" + ProvinceUtil.getProvinceCode(province);
            return enterpriseMapper.pageList(page, tableName, enterprise);
        } catch (Exception e) {

            throw new BusinessException("分页查询企业信息失败");
        }
    }

    @Override
    public Boolean save(Enterprise enterprise) {
        Boolean b=enterpriseMapper.save(enterprise);
        return b;
    }

    @Override
    public boolean removeById(Long id) {
        Boolean b=enterpriseMapper.removeById(id);
        return b;
    }

    @Override
    public boolean update(Enterprise enterprise) {
        Boolean b=enterpriseMapper.update(enterprise);
        return b;
    }

    @Override
    public List<Map<String, Object>> enterpriseInfo(Enterprise enterprise, String province) {

        return enterpriseMapper.enterpriseInfo(enterprise,province);
    }

    @Override
    public Enterprise fuzzySearchByNsrsbh(String nsrsbh, String base) {

        if (StringUtils.isBlank(base)) {
            throw new IllegalArgumentException("省份不能为空");
        }
        String tableName = "enterprise_" + ProvinceUtil.getProvinceCode(base);
        return enterpriseMapper.fuzzySearchByNsrsbh(tableName,nsrsbh);

    }


}

